{{ $headers := findRE "<h[1-4].*?>(.|\n])+?</h[1-4]>" .Content }}
<!-- at least one header to link to -->
{{ if ge (len $headers) 1 }}
	<div class="toc-content">
	<!-- ignore empty links with + -->
		{{ $h1_n := len (findRE "(.|\n])+?" .Content) }}
		{{ $re := (cond (eq $h1_n 0) "<h[2-4]" "<h[1-4]") }}
		{{ $renum := (cond (eq $h1_n 0) "[2-4]" "[1-4]") }}
		<center>- CATALOG -</center>
			{{ range $headers }}
				{{ $header := . }}
				{{ range first 1 (findRE $re $header 1) }}
					{{ range findRE $renum . 1 }}
						{{ $next_heading := (cond (eq $h1_n 0) (sub (int .) 1 ) (int . ) ) }}
						{{ range seq $next_heading }}
							<ul>
						{{ end }}
						{{ $anchorId :=  (replaceRE ".* id=\"(.*?)\".*" "$1" $header ) }}
								<li>
				 					<a href="#{{ $anchorId }}" v-on:click="closeDrawer" id="{{ $anchorId }}-nav">
										 {{ $header | plainify | htmlUnescape }}
									</a>
								</li>
						{{ range seq $next_heading }}
							</ul>
						{{ end }}
					{{ end }}
				{{ end }}
			{{ end }}
	</div>
{{ end }}
